package com.course.service.impl;

import com.course.entity.ResultBody;
import com.course.mapper.PostMapper;
import com.course.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class PostServiceImpl implements PostService {
    @Autowired
    private PostMapper postMapper;
    @Override
    public ResultBody getpost(Map<String,Object> map)
    {
        if(postMapper.addpost(map)>0)
        {
            return new ResultBody(200,"添加成功",true);
        }
        else
        {
            return new ResultBody(500,"添加失败",false);
        }
    }
    @Override
    public ResultBody displaypost()
    {
        if(postMapper.displaypost()!=null||postMapper.displaypost()==null)
        return new ResultBody(200,"查询成功",postMapper.displaypost(),postMapper.displaypost().size());
        else
            return new ResultBody(500,"查询失败",false);
    }

    @Override
    public ResultBody addcomment(Map<String,Object> map)
    {
        if(postMapper.addcomment(map)>0)
        {
            return new ResultBody(200,"评论成功",true);
        }
        else
        {
            return new ResultBody(500,"评论失败",false);
        }
    }

    @Override
    public ResultBody displaycomment(Map<String,Object> map)
    {
        System.out.println(map);
        System.out.println(postMapper.displaycomment(map));
        if(postMapper.displaycomment(map)!=null||postMapper.displaycomment(map)==null)
        return new ResultBody(200,"查询成功",postMapper.displaycomment(map),postMapper.displaycomment(map).size());
        else
            return new ResultBody(500,"查询失败",false);
    }

    @Override
    public ResultBody deletepost(Map<String,Object> map)
    {
        if(postMapper.deletepost(map)>0)
        {
            return new ResultBody(200,"删除成功",true);
        }
        else
        {
            return new ResultBody(500,"删除失败",false);
        }
    }
}
